PRO CONSOLIDATE_FFORE_GRID, suff
  
  NBLOCK=32
  
  IF n_elements(suff) EQ 0 THEN suff = ''
  fn = FILE_SEARCH('./irdc_dist_model/data/case3_irdc_grid'+suff+$
                   '_block*.sav',count=nf)
  
  IF nf NE 32 THEN BEGIN
     print,nf
     message,'Hold your horses!  Not done computing the full grid.',/inf
  ENDIF
  
  ;; Define total grid sizes
  n_A = 51L
  n_B = 41L
  n_C = 41L
  n_Td = 81L
  A = dindgen(n_A)/100.d
  Td = dindgen(n_Td)*0.25d + 10.d
  
  total_grid = fltarr(n_A,n_B,n_C,n_Td)+1.d8
  
  FOR i=0L,nf-1 DO BEGIN
     
     ;; For each file, extract the block # & Td indices
     name = strmid(fn[i],strpos(fn[i],'block'),strpos(fn[i],'.sav')-$
                   strpos(fn[i],'block'))
     
     message,'Restoring GRID for '+name,/inf
     
     block = fix(strmid(name,5))
     
     i0 = long(round(float(block - 1)/float(NBLOCK)*float(n_Td)))
     i1 = long(round(float(block)/float(NBLOCK)*float(n_Td)))-1
     
     restore,fn[i]
     total_grid[*,*,*,i0:i1] = grid
     
  ENDFOR
  
  print,m4_stat(total_grid)
  
  ;; Convert chi^2 to probability
  grid = exp( -total_grid / 2.d )
  
  print,size(grid,/DIM)
  colB = total(grid,2,/NaN)
  print,size(colB,/DIM)
  colB = total(colB,2,/NaN)
  print,size(colB,/DIM)
  
  ;; Convert back to chi^2
  
  grid = -2.d * alog(colB)
  
  shade_surf,grid,A,Td,xr=[0,0.5],yr=[10,30],zr=[min(grid),min(grid)+100]
  
  
  save,grid,filename='./irdc_dist_model/data/case3_irdc_grid'+suff+'_AT.sav'
  
  
END
